package com.esunny.springboot.service.impl;

import com.esunny.springboot.mapper.NewsMapper;
import com.esunny.springboot.mapper.UserMapper;
import com.esunny.springboot.pojo.entity.NewsInf;
import com.esunny.springboot.pojo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class NewsManagerImpl {
    @Autowired
    private NewsMapper newsMapper;
    @Autowired
    private UserMapper userMapper;

    @Transactional(rollbackFor = Exception.class)
    public void cacheTest() {
        newsMapper.updateNews("测试", 1);
        int i=1/0;
    }

    public void update() {
        try {
            // 线程暂停10ms，是为了模拟让另外一条线程在此处获得CPU的情形
            Thread.sleep(10);
        } catch (Exception ex) {
        }
        newsMapper.updateNews("测试", 1);
    }

    @Transactional(transactionManager = "", propagation = Propagation.REQUIRED)
    public void update1() {
        try {
            // 线程暂停10ms，是为了模拟让另外一条线程在此处获得CPU的情形
            Thread.sleep(10);
        } catch (Exception ex) {
        }
        newsMapper.updateNews("测试", 1);
    }
}
